package org.example.taobao.demo.order.controller;

import lombok.RequiredArgsConstructor;
import org.example.taobao.demo.order.service.OrderService;
import org.example.taobao.demo.order.vo.PurchaseGoodVO;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author liwei
 * @date 2022/6/11 6:34 PM
 */
@RestController
@RequestMapping("/api/order")
@RequiredArgsConstructor
public class OrderController {
    private final OrderService orderService;

    @PostMapping
    public String purchase(@RequestBody PurchaseGoodVO purchaseGoodVO) {
        boolean result = orderService.purchase(purchaseGoodVO.getGoodId(), purchaseGoodVO.getNumber());
        return result ? "购买成功" : "扣减库存失败";
    }
}
